﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace SDSystem.Models
{
    internal class ServiceMaintainMeta
    {
        [Required(ErrorMessage = "Service Name is required")]
        [DisplayName("Service Name")]
        public string ServiceName { get; set; }

        [Required(ErrorMessage = "Service Short Description is required")]
        [DisplayName("Service Short Description")]
        public string ServiceShortDes { get; set; }

        //[Required(ErrorMessage = "Contact is required")]
        //[DisplayName("Lead Contact")]
        //public string ContactId { get; set; }
        [Required(ErrorMessage = "Dept Code is required")]
        [DisplayName("Dept Code")]
        public string DeptCode { get; set; }

        [Required(ErrorMessage = "Service Type is required")]
        [DisplayName("Service Type")]
        public string ServiceType { get; set; }

        //[Required(ErrorMessage = "Funding Contact Detail is required")]
        //public int FundingContactDetail { get; set; }
        //[Required(ErrorMessage = "Funding Amount is required")]
        //public decimal FundingAmount { get; set; }
    //    public DateTime ServiceStartDate { get; set; }

    //    [GreaterThanDate("ServiceStartDate")]
    //    public DateTime ServiceEndDate { get; set; }

    //    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    //    {
    //        if (ServiceEndDate <= ServiceStartDate)
    //        {
    //            yield return new ValidationResult("EndDate must be greater than StartDate", new string[] { "ServiceEndDate" });
    //        }
    //    }
    //}

    //public class GreaterThanDateAttribute : ValidationAttribute, IClientValidatable
    //{
    //    public GreaterThanDateAttribute(string otherPropertyName)
    //        : base("{0} must be greater than {1}")
    //    {
    //        this.OtherPropertyName = otherPropertyName;
    //    }

    //    public string OtherPropertyName { get; set; }

    //    public override string FormatErrorMessage(string name)
    //    {
    //        return String.Format(this.ErrorMessageString, name, this.OtherPropertyName);
    //    }

    //    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    //    {
    //        var otherPropertyInfo = validationContext.ObjectType.GetProperty(this.OtherPropertyName);
    //        var otherDateObj = otherPropertyInfo.GetValue(validationContext.ObjectInstance, null);

    //        if (otherDateObj == null || value == null)
    //        {
    //            return null;
    //        }

    //        var otherDate = (DateTime) otherDateObj;
    //        var thisDate = (DateTime) value;

    //        if (thisDate <= otherDate)
    //        {
    //            var message = this.FormatErrorMessage(validationContext.DisplayName);
    //            return new ValidationResult(message);
    //        }

    //        return null;
    //    }

    //    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
    //        ModelMetadata metadata, ControllerContext context)
    //    {
    //        var rule = new ModelClientValidationRule();
    //        rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
    //        rule.ValidationType = "vtype[greater]";

    //        // instead vtype you can use Validator
    //        // rule.ValidationType = "validator[greater]";
    //        // in this case 'greater' must be defined js function

    //        rule.ValidationParameters.Add("other", this.OtherPropertyName);
    //        yield return rule;
    //    }
    }
}

